21. Manipulating Normals

Quiz: Raises (X+a)

In [1]:
# just a helper function for easier youtube call
def strip_url(url):
    return url.replace('https://youtu.be/','')

from IPython.display import YouTubeVideo
url = 'https://youtu.be/pXQnqZlrsXY'
YouTubeVideo(strip_url(url))
Out[1]:

Ans:

It is hard to imagine how salary turns out to be normal as I am unable to comprehend binomial nature underlying it (what would it be, to give salary or not?). Nevertheless, here we go.

Considering as discrete random variable problem..

Mean:
$ \textstyle \begin{array}{l} \mu = E[X] = \dfrac {X_1 + X_2 + \cdots + X_n}{n} \\ \mu' = E[X+a] = \dfrac { (X_1+a) + (X_2+a) + \cdots + (X_n+a)}{n} \\ = \dfrac {X_1 + X_2 + \cdots + X_n + (n \cdot a)}{n} \\ = \dfrac {X_1 + X_2 + \cdots + X_n}{n} + a \\ = E[X] + a \\ = \mu + a \\ \text {Given } \mu = 60000 \ a = 10000 , \\ \mu' = \mu + a = 60000+10000 = 70000 \end{array} \\ \\ $

Variance:
$ \require{cancel} \begin{array}{l} \sigma^2 = Var[X] = E[X^2] - [E[X]]^2 \\ \sigma'^{\ 2} = E[(X+a)^2] - [E[(X+a)]]^2 \\ = E[X^2 + a^2 + 2aX] - [E[X] + E[a]]^2 \\ = E[X^2] + a^2 + 2aE[X] - \Big\{ [E[X]]^2 + a^2 + 2aE[X] \Big\} \\ = E[X^2] + \cancel{a^2} + \cancel{2aE[X]} - [E[X]]^2 - \cancel{a^2} + \cancel{2aE[X]} \\ = E[X^2] - [E[X]]^2 \\ = \sigma^2 \\ \text {Given } \sigma^2 = 10000, \\ \sigma'^{\ 2} = 10000 \end{array} \\ \\ $

Thus, remember,

$$ \color {blue}{ \text{If }\ X' = X + a, \text{then}} \\ \\ \color {blue}{ \mu' = \mu + a} \\ \\ \color {blue}{ \sigma'^{\ 2} = \sigma^2} \\ \\ $$

Using continous density function..

It is also possible, and straight forward that we could deduce the same as shown in Udacity, that from Normal distribution function, we could derive the same.

$ \textstyle \begin{array}{l} x' = x + a \\ \therefore x = x' - a \\ \mu = E[X] \\ \mu' = E[X+a] \\ \varphi(x) = \dfrac {1}{\sigma \sqrt{2\pi}}e^{-\dfrac{1}{2} \Big( \dfrac{x-\mu}{\sigma} \Big)^2 } \\ = \dfrac {1}{\sigma \sqrt{2\pi}}e^{-\dfrac{1}{2} \Big( \dfrac{x' - a -\mu}{\sigma} \Big)^2 } \\ = \dfrac {1}{\sigma \sqrt{2\pi}}e^{-\dfrac{1}{2} \Big( \dfrac{x' - (\mu + a)}{\sigma} \Big)^2 } \\ \\ \therefore \text {new Mean} \ \mu' = \mu + a, \text {but Variance did not change} \ \sigma'^{\ 2} = \sigma^2 \end{array} $

Double Salary (aX)

In [2]:
url = 'https://youtu.be/Gc42YG3335w'
YouTubeVideo(strip_url(url))
Out[2]:

Ans

Considering as discrete random variable problem...

Mean:
$ \textstyle \begin{array}{l} \mu = E[X] = \dfrac {X_1 + X_2 + \cdots + X_n}{n} \\ \\ \mu' = E[aX] = \dfrac { (aX_1) + (aX_2) + \cdots + (aX_n)}{n} \\ \\ = \dfrac {a(X_1 + X_2 + \cdots + X_n)}{n} \\ \\ = aE[X] \\ = a\mu \\ \text {Given } \mu = 70000 \ a = 2 , \\ \mu' = a\mu = 2(70000) = 140000 \end{array} \\ \\ $

If you noticed, we already used this property of scaling mean, in Var(X) proof in earlier quiz. We will also use now.

Variance:
$ \textstyle \begin{array}{l} \sigma^2 = Var[X] = E[X^2] - [E[X]]^2 \\ \sigma'^{\ 2} = E[(aX)^2] - [E[(aX)]]^2 \\ = a^2E[X^2] - [aE[X]]^2 \\ = a^2E[X^2] - a^2[E[X]]^2 \\ = a^2 \big\{ E[X^2] - [E[X]]^2\big\} = a^2\sigma^2 \\ \text {Given }\ \sigma = 10000, a = 2, \\ \sigma'{\ ^2} = 2^2(10000^2) = (20000)^2 \\ \therefore \sigma' = 20000 \end{array} \\ \\ $

Using Continous density function

$ \textstyle \begin{array}{l} x' = ax \\ \therefore x = \dfrac{x'}{a} \\ \mu = E[X] \\ \mu' = E[aX] \\ \varphi(x) = \dfrac {1}{\sigma \sqrt{2\pi}}e^{-\dfrac{1}{2} \Big( \dfrac{x-\mu}{\sigma} \Big)^2 } \\ = \dfrac {1}{\sigma \sqrt{2\pi}}e^{-\dfrac{1}{2} \Bigg( \dfrac{\frac{x'}{a} -\mu}{\sigma} \Bigg)^2 } \\ = \dfrac {1}{\color {blue}{\sigma} \sqrt{2\pi}}e^{-\dfrac{1}{2} \Big( \dfrac{x' - \color {blue}{a\mu}}{\color {blue}{a\sigma}} \Big)^2 } \\ \end{array} \\ \\ $

Note: As sigma is not scaled by factor "a" in exponential part, curve would now be taller unless we compensate by dividing the constant by "a" as shown below (I am not fully convinced though, can some one prove it mathematically more rigorously?)

$ \varphi(x) = \dfrac {1}{\color {blue}{a\sigma} \sqrt{2\pi}}e^{-\dfrac{1}{2} \Big( \dfrac{x' - \color {blue}{a\mu}}{\color {blue}{a\sigma}} \Big)^2 } \\ \therefore \text {new Mean} \ \mu' = a\mu, \text {and Variance} \ \sigma'^{\ 2} = a^2\sigma^2 \\ \\ $

Thus, remember,

$$ \color {blue}{ \text{If }\ X' = aX, \text{then}} \\ \\ \color {blue}{ \mu' = a\mu} \\ \\ \color {blue}{ \sigma'^{\ 2} = a^2\sigma^2} \\ \\ $$

Throwing (aX+b)

In [3]:
url = 'https://youtu.be/Piq_2B6udhQ'
YouTubeVideo(strip_url(url))
Out[3]:

Ans:

$ X' = aX + b $

Mean: $ \mu = E[X] \\ \mu' = E[X'] = E[aX + b] = aE[X] + b \\ \text {Given } \ \mu=70000, \sigma=10000, a=(100+10)\%,\ b=2 \\ \mu' = (1.1)(30) + 2 = 33 + 2 = 35 \\ \\ $

Variance: $ \sigma^2 = Var(X) \\ \sigma'{\ ^2} = Var(X') = E[X'{\ ^2}] - [E[X']]^2 \\ = E[(aX+b)^2] - [E[aX+b]]^2 \\ = E[a^2X^2 + b^2 + 2abX] - (aE[X]+b)^2 \\ = E[a^2X^2 + b^2 + 2abX] - (a^2[E[X]]^2 + b^2 + 2abE[X]) \\ = a^2E[X^2] + b^2 + 2abE[X] - a^2[E[X]]^2 - b^2 - 2abE[X] \\ = a^2E[X^2] - a^2[E[X]]^2 = a^2(E[X^2] - [E[X]]^2) = a^2\sigma^2 \\ \text {Given } \ \mu=30, \sigma=5, a=(100+10)\%, \ b=2 \\ \sigma' = a\sigma = (1.1)(5) = 5.5 $

Thus, remember,

$$ \color {blue}{ \text{If }\ X' = aX + b, \text{then}} \\ \\ \color {blue}{ \mu' = a\mu + b} \\ \\ \color {blue}{ \sigma'^{\ 2} = a^2\sigma^2} \\ \\ $$

Golf 1 (X+Y)

In [4]:
url = 'https://youtu.be/CvnqL5oSXrw'
YouTubeVideo(strip_url(url))
Out[4]:

.. and also find combined variance..

Ans

$ X' = X + Y \\ \mu_x = E[X] = 100, \sigma_x = 30 \\ \mu_y = E[Y] = 100, \sigma_y = 30 \\ $

$ \mu' = E[X+Y] = E[X] + E[Y] \\ = 100 + 100 = 200 \\ $

$ \sigma'^{\ 2} = Var(X') = E[X'{\ 2}] - [E[X']]^2 \\ = E[(X + Y)^2] - \big\{ E[X + Y] \big\}^2 \\ = E[X^2 + Y^2 + 2XY] - \big\{ E[X] + E[Y] \big\}^2 \\ = E[X^2] + E[Y^2] + 2E[X]E[Y] - \big\{ [E[X]]^2 + [E[Y]]^2 + 2E[X]E[Y] \\ = \big\{ E[X^2] - [E[X]]^2 \big\} + \big\{ E[Y^2] - [E[Y]]^2 \big\} \\ = \sigma_x^2 + \sigma_y^2 = 30 + 30 = 60 $

Thus, remember,

$$ \color {blue}{ \text{If }\ X' = X + Y, \text{then}} \\ \\ \color {blue}{ \mu' = \mu_X + \mu_y} \\ \\ \color {blue}{ \sigma'^{\ 2} = \sigma_x^2 + \sigma_y^2} \\ \\ $$

Subtracting Normals (X-Y)

In [5]:
url = 'https://youtu.be/FpmwhVT7ikU'
YouTubeVideo(strip_url(url))
Out[5]:

$ X' = X - Y \\ X \neq Y, \ \ E[X] = E[Y] = \mu \ \text{and} \ Var(X) = Var(Y) = \sigma \\ $

$ \mu' = E[X'] = E[X-Y] = E[X] - E[Y] = E[X] - E[X] = \mu - \mu = 0 \\ $

$ \sigma'{\ ^2} = Var(X') = E[X'{\ 2}] - [E[X']]^2 = E[ (X-Y)^2 ] - [ E[X-Y] ]^2 \\ = E[ X^2 + Y^2 - 2XY ] - \big\{ E[X] - E[Y] \big\}^2 \\ = E[X^2] + E[Y^2] - 2E[X][Y] - [E[X]]^2 - [E[Y]]^2 + 2E[X][Y] \\ = \big\{ E[X^2] - [E[X]]^2 \big\} + \big\{ E[Y^2] - [E[Y]]^2 \big\} \\ = \sigma + \sigma = 2\sigma $

Thus, remember,

$$ \color {blue}{ \text{If }\ X' = X - Y, \text{then}} \\ \\ \color {blue}{ \mu' = \mu_X - \mu_y} \\ \\ \color {blue}{ \sigma'^{\ 2} = \sigma_x^2 + \sigma_y^2} \\ \\ $$


Note that even when you subtract, the variance adds up, which is very counter intuitive, so we have to be careful

Note: The few left out quizes in this section are simple and can be easily answered from above formulae, so skipped.